#!/usr/bin/env python3

from functools import wraps


def logged(func):

    def with_logging(*args, **kwargs):
        print(func.__name__ + " was called")
        return func(*args, **kwargs)
    return with_logging


def w_logged(func):
    """
    wraps可以把原函数的属性复制给被装饰的函数对象
    """

    @wraps(func)
    def with_logging(*args, **kwargs):
        print(func.__name__ + " was called")
        return func(*args, **kwargs)
    return with_logging

@logged
def eat(foods):
    print("eating some %s" % foods)

@w_logged
def w_eat(foods):
    print("eating some %s" % foods)

if __name__ == "__main__":
    #  eat("rice")
    eat = logged(eat)
    print(eat.__name__)
    w_eat = w_logged(w_eat)
    print(w_eat.__name__)
